To make a stitching operation automatic, it is often necessary to detect, at the end of stitching, the presence of the edge of the material which intersects the stitching line, so as to be able to determine the distance separating this edge from the needle and to control stopping of the stitching if it is not to reach said edge. This requirement is met with, either when the two pieces of material to be stitched together have their edges superimposed, or when it is a question of stitching a piece of material in the middle of a larger piece. It is also met with during overstitching.